/*
 * @Author: your name
 * @Date: 2021-12-12 23:25:40
 * @LastEditTime: 2022-01-06 10:14:52
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \code\single-spa\parent-vue\src\main.js
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import { registerApplication, start } from 'single-spa'
Vue.config.productionTip = false

async function loadScript(url) {
  return new Promise((resolve,reject) => {
    const script = document.createElement('script')
    script.src = url
    script.onload = resolve
    script.onerror = reject
    document.body.appendChild(script)
  })
}

registerApplication('myAppVue',
  async () => {
    await loadScript('http://localhost:10000/js/chunk-vendors.js')
    await loadScript('http://localhost:10000/js/app.js')
    console.log('加载模块', window, window.singleVue)
    return window.singleVue
  },
  location => location.pathname.startsWith('/vue')
)

new Vue({
  router,
  store,
  mounted() {
    // 启动
    start()
  },
  render: h => h(App)
}).$mount('#app')
